/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package factoryTotal;

import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
/**
 *
 * @author wida46984148
 */
public class NaveEnemiga2 extends NaveBaseEnemiga {

    boolean enemigo = true;
    Timer timer;
    ElementosJuego a;
    Disparo shoot2 = null;
    Disparo msE = null;
    Disparo msE2 = null;
    NaveBase nbE = null;
    boolean disparando = true;

    public NaveEnemiga2(float vida, float vidaT, Disparo shoot, Disparo shoot2, Image nau, float posX, float posY, Image nauDestroy) {
        super(vida, vidaT, shoot, nau, nauDestroy);
        super.pX = posX;
        super.pY = posY;
        arrayDisparosE = new ArrayList<Disparo>();
        this.shoot2 = shoot2;
    }

    @Override
    public void posicion(float posX, float posY) {
        super.posicion(posX, posY);
        super.s = new Rectangle(posX, posY, nave.getWidth(), nave.getHeight());
    }

    @Override
    public void render(GameContainer gc, Graphics g) {
        if(!(super.isMort())){
            g.drawImage(nave, pX, pY);
        }else{
            g.drawImage(explosion, pX, pY);
        }
        for (Disparo n : arrayDisparosE) {
            if (n != null) {
                n.render(gc, g);
            }
        }
    }

    @Override
    public void update(int delta) throws SlickException {
        if (!(destruido)) {
            pY += 0.3f;
            s.setLocation(pX, pY);
            if (disparando) {
                disparando = false;
                timer = new Timer(600, new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        msE = disparo.copiarDisparo();
                        msE.posicion(pX+10, pY+20);
                        msE2 = shoot2.copiarDisparo();
                        msE2.posicion(pX+20, pY+20);
                        //a.posShootE(nbE.getPosX() + 58, nbE.getPosY() + 100, (shootE) msE);
                        arrayDisparosE.add(msE);
                        arrayDisparosE.add(msE2);
                        if (900 <= getPosY()) {
                            timer.stop();
                            destruido = true;
                        }
                    }
                });
            }
            timer.start();
        } else {
            pX = 1300;
            pY = 1300;
        }
        updateDisparos(delta);
    }

    @Override
    public void updateDisparos(int delta) {
        timer.start();
        for (Disparo n : arrayDisparosE) {
            if (n != null) {
                n.update(delta);
            }
        }
    }
}

